package com.project.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.ExpertBean;
import com.project.service.ExpertService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("expert")
public class ExpertController {

    @Resource
    private ExpertService expertService;

    //显示所有专家信息
    @RequestMapping("findAllExpert")
    @ResponseBody
    public IPage<ExpertBean> findAllExpert(@RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                           @RequestParam(value = "pageSize", defaultValue = "3") int pageSize) {
        return expertService.findAllExpert(pageNo, pageSize);
    }


    //添加专家
    @RequestMapping("addExpert")
    @ResponseBody
    public String addExpert(ExpertBean expertBean) {
        expertService.addExpert(expertBean);
        return "ok";
    }


    //查看详细信息
    @RequestMapping("findId")
    @ResponseBody
    public ExpertBean findId(int exId) {
        return expertService.findId(exId);
    }


    //修改信息
    @RequestMapping("updateExpert")
    @ResponseBody
    public String updateExpert(int exId, int expertId, String expertTel, String expertDuty,
                               String expertWork, String expertEmail) {
        expertService.updateExpert(expertId, expertTel, expertDuty, expertWork, expertEmail);
        return "ok";
    }


    //删除信息
    @RequestMapping("delExpert")
    @ResponseBody
    public String delExpert(int exId) {
        expertService.delExpert(exId);
        return "ok";
    }


    //模糊查询
    @RequestMapping("findName")
    @ResponseBody
    public IPage<ExpertBean> findName(@RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                      @RequestParam(value = "pageSize", defaultValue = "3") int pageSize,
                                      String expertName, String expertSpecialty,
                                      String expertWork) {
        return expertService.findName(pageNo, pageSize, expertName, expertSpecialty, expertWork);
    }

}
